<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <title>上传照片</title>
  <include file="Tpl/AppHome/css.html" />
  <script src="/Public/App/assets/jquery/jquery.js"></script>
  <script src="/Public/App/assets/mui/mui.min.js"></script>

</head>

<body id="photo_info">
  <header>
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left white"></a>
    <h1 class="mui-title white" style="top: 0px;">图片上传</h1>
  </header>
  <section>
    <div class="list">
      <!-- <div class='mui-table-view-cell mui-media'> -->
      <div class="upload">
        <img id="headimg" class="headimg" height="280px;" width="280px" src="/Public/App/images/gou.png">
        <p class="imageup">
          上传图片
        </p>
        <div class="auto_number">
          <span>自动识别</span>123456
        </div>
        <div class="number">
          <span>自行输入</span>
          <input type="number" placeholder="可自行输入">
        </div>

        <button class='button' disabled="disabled" onclick="upload()"> 提交</button>

      </div>

    </div>
  </section>
  <!-- <script>
    require(["js/photo/info"])
  </script> -->
  <script>
    //扩展API完成后执行的操作
    function plusReady() {
      //给选中的li增加判别class
      $(".upload").on("tap", "p", function () {

        var $divs = $(this).parents(".upload");
        $divs.addClass("selectD");
        $divs.siblings().removeClass("selectD");
        page.imgUp();
      })
    }




    //弹出系统按钮选择框
    var page = null;
    page = {
      imgUp: function () {
        var m = this;
        /* console.log(m);*/
        plus.nativeUI.actionSheet({
          cancel: "取消",
          buttons: [{
            title: "拍照"
          }]
        }, function (e) { //1 是拍照
          switch (e.index) {
            case 1:
              appendByCamera();
              break;
          }
        });
      }
    }
    // 拍照添加文件
    function appendByCamera() {
      plus.camera.getCamera().captureImage(function (e) {


        console.log("e is" + e);
        plus.io.resolveLocalFileSystemURL(e, function (entry) {
 var path = entry.toRemoteURL();

          console.log(path, "1111111111")
          console.log($(".headimg")[0].src, "默认src")
          $(".headimg")[0].src = path;
          console.log($(".headimg")[0].src, "展示src1")
          var btnArray = ['重拍', '确认'];
          mui.confirm("是否用这张", "提示", btnArray, function (e) {
            if (e.index == 1) {
              console.log($(".headimg")[0].src, "展示src2")
              $(".headimg")[0].src = path;
              console.log($(".headimg")[0].src, "确认src3")
              $("#headimg").addClass("upImg")
              mui.confirm("上传成功")
              if ($("#headimg").hasClass("upImg")) {
                $("button").removeAttr("disabled")
              }
              //      这里发送自动识别请求
            } else {
              appendByCamera()
            }
          })
        }, function (e) {
          mui.toast("读取拍照文件错误：" + e.message);
        });

      });
    }


    // //服务端接口路径
    // var server = "http://www.test.cn/aaa.php";
    // //获取图片元素
    // var files = document.getElementById('headimg');
    // // 上传文件
    function upload() {
      mui.confirm("hehe")
      // var wt = plus.nativeUI.showWaiting();
      // var task = plus.uploader.createUpload(server, {
      //   method: "POST"
      // },
      //   function (t, status) { //上传完成
      //     if (status == 200) {
      //       alert("上传成功：" + t.responseText);
      //       wt.close(); //关闭等待提示按钮
      //     } else {
      //       alert("上传失败：" + status);
      //       wt.close(); //关闭等待提示按钮
      //     }
      //   }
      // );
      // //添加其他参数
      // task.addData("name", "test");
      // task.addFile(files.src, {
      //   key: "dddd"
      // });
      // task.start();
    }


    //    判断点击的是上传的第几个li             


    //扩展API是否准备好，如果没有准备好则监听plusReady 
    if (window.plus) {
      plusReady();
    } else {
      document.addEventListener("plusready", plusReady, false);
    }
  </script>
</body>


</html>